//! @Author: DengLibin
//! @Date: Create in 2024-01-10 12:05:21
//! @Description: 错误

use std::fmt::Display;

#[derive(Debug, Clone, PartialEq)]
pub struct CommonError {
    msg: String,
}
impl std::fmt::Display for CommonError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(f, "Message: {}", self.msg)
    }
}
// 自定义结果
pub type CommonResult<T> = std::result::Result<T, CommonError>;

//转换结果
pub fn to_common_result<T, E: Display>(result: Result<T, E>) -> CommonResult<T> {
    return match result {
        Ok(r) => Result::Ok(r),
        Err(err) => Result::Err(CommonError {
            msg: err.to_string(),
        }),
    };
}